package com.itcat.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itcat.api.mysql.PmsProductLadderApi;
import com.itcat.mapper.PmsProductLadderMapper;
import com.itcat.mysql.pojo.PmsMemberPrice;
import com.itcat.mysql.pojo.PmsProductFullReduction;
import com.itcat.mysql.pojo.PmsProductLadder;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author Jerry Broker
 * @project_name rainbow-mall
 * @create 2022-04-04 0:30
 */
@DubboService
public class PmsProductLadderApiImpl implements PmsProductLadderApi {

    @Autowired
    private PmsProductLadderMapper pmsProductLadderMapper;


    /**
     * 保存商品阶梯价格设置
     * @param PmsProductLadderList
     */
    @Override
    public void saveList(List<PmsProductLadder> PmsProductLadderList) {
        pmsProductLadderMapper.batchInsert(PmsProductLadderList);
    }

    /**
     * 商品阶梯价格设置
     * @param productId
     * @return
     */
    @Override
    public List<PmsProductLadder> findByProductId(Long productId) {
        LambdaQueryWrapper<PmsProductLadder> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(PmsProductLadder::getProductId, productId);
        List<PmsProductLadder> pmsProductLadderList = pmsProductLadderMapper.selectList(queryWrapper);
        return pmsProductLadderList;
    }

    /**
     * 更新商品阶梯价格设置
     * @param productLadderList
     */
    @Override
    public void updateList(List<PmsProductLadder> productLadderList) {
        pmsProductLadderMapper.batchUpdate(productLadderList);
    }

    /**
     * 删除响应商品id的数据
     * @param productId
     */
    @Override
    public void deleteByProductId(Long productId) {
        LambdaQueryWrapper<PmsProductLadder> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(productId != null, PmsProductLadder::getProductId, productId);
        pmsProductLadderMapper.delete(queryWrapper);
    }
}
